/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author tien
 */
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;

public class BoyController extends Controller{
    private boolean previousFire = false;
    
    private boolean fire = false;
    private boolean move = false;
    
    private boolean previousGoBack = false;
    
    public BoyController(Moveable moveable) {
        super(moveable);
    }
    
    public void setFire(boolean isfire) {
        this.previousFire = fire;
        fire = isfire;
    }
    
    public void setMove(boolean ismove) {
        move = ismove;
    }
    
    public void update() {
        boolean canMove = moveable.checkCollideAndSolve();
        if (canMove) {
            this.previousGoBack = false;
            if (moveable.changeDirection()) {
                moveable.turn();
            }
            else {
                if (move) {
                    moveable.keepMoving();
                }
            }
        }
        else {
            if (!this.previousGoBack) {
                moveable.goBack();
                this.previousGoBack = true;
            }
        }
        if (fire && !previousFire) {
            try {
                moveable.fire();
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
